/*
 * Copyright 2008 Neil Bacon
 * Distributed under the terms of the Mozilla Public License version 1.1
 * or the GNU General Public License version 3.
 */

package nb.xadd.node.impl;

import nb.xadd.node.Node;
import nb.xadd.operator.BinaryOperator;

/**
 * Constant value terminal node.
 */
public class ConstantValueNode extends AbstractValueNode {

    private final int hashCode;

    protected ConstantValueNode(double constValue) {
        super(constValue);
        hashCode = calcHashCode();
    }

    @Override
    public int hashCode() {
        return hashCode;
    }

    @Override
    public Ordering getOrdering() {
        return Ordering.CONSTANT;
    }

    // Don't care about ordering of one ConstantValueNode w.r.t. another.
    //	@Override
    //	public int compareTo(Node other) {
    //		int i = super.compareTo(other);
    //		if (i != 0) {
    //			return i;
    //		}
    //		ConstantValueNode n = (ConstantValueNode) other;
    //		return Double.compare(getConstValue(), n.getConstValue());
    //	}

    @Override
    public int getPolynomialOrder() {
        return 0;
    }

    //	@Override
    //	public double evaluate(DataModel model) {
    //		return getConstValue();
    //	}
    //
    @Override
    public Node apply(BinaryOperator binaryOperator, Node node) {
        return node.applyConstantValue(binaryOperator, this);
    }

    @Override
    public Node applyConstantValue(BinaryOperator binaryOperator, ConstantValueNode node) {
        return binaryOperator.executeConstantConstant(node, this);
    }

    @Override
    public Node applyLinearValue(BinaryOperator binaryOperator, LinearValueNode node) {
        return binaryOperator.executeConstantLinear(this, node);
    }

    @Override
    public Node applyPolynomialValue(BinaryOperator binaryOperator, PolynomialValueNode node) {
        return binaryOperator.executeConstantPolynomial(this, node);
    }

    @Override
    public Node applyBooleanDecision(BinaryOperator binaryOperator, BooleanDecisionNode node) {
        return binaryOperator.executeConstantBooleanDecision(this, node);
    }

    @Override
    public Node applyRealEqualDecision(BinaryOperator binaryOperator, RealEqualDecisionNode node) {
        return binaryOperator.executeConstantRealEqualDecision(this, node);
    }

    @Override
    public Node applyRealGreaterOrEqualDecision(BinaryOperator binaryOperator, RealGreaterOrEqualDecisionNode node) {
        return binaryOperator.executeConstantRealGreaterOrEqualDecision(this, node);
    }
    
    @Override
    public void appendTo(int depth, StringBuilder buf) {
        super.appendTo(depth, buf);
        buf.append("\n");
    }
        
}
